<template>
  <el-container>
    <el-header>
      <div class="header">
        <el-menu
            router
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
          <div class="header-title">
            <h1 style="color: white">Food Bear</h1>
          </div>
          <el-menu-item index="/foodIndex" :class="$route.path==='/foodIndex'?'is-active':''">首页</el-menu-item>
          <div class="header-user" v-if="login">
            <el-link :underline="false" href="/login"><span style="color: white">请登录</span></el-link>
          </div>
          <div class="header-user" v-if="!login">
            <template>
              <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link" style="color: white">
                  欢迎！{{name}}<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item >退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </div>
        </el-menu>
      </div>
    </el-header>
    <el-container>
      <el-aside width="16%" style="margin-top: 20px;height: 650px">
        <el-menu
            router
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>经销商管理</span>
            </template>
            <el-menu-item index="/auditOverview" :class="$route.path === '/auditOverview'?'is-active':''">审核总览</el-menu-item>
            <el-menu-item index="/agentList" :class="$route.path==='/agentList'?'is-active':''">管理经销商</el-menu-item>
          </el-submenu>
          <el-menu-item index="/contractManagement" :class="$route.path==='/contractManagement'?'is-active':''">
            <i class="el-icon-menu"></i>
            <span slot="title">合同编写</span>
          </el-menu-item>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-document"></i>
              <span slot="title">产品管理</span>
            </template>
            <el-menu-item index="/addProduct" :class="$route.path==='/addProduct'?'is-active':''">添加产品</el-menu-item>
            <el-menu-item index="/orderListRecord" :class="$route.path==='/orderListRecord'?'is-active':''">销售记录</el-menu-item>
            <el-menu-item index="/productList" :class="$route.path==='/productList'?'is-active':''">产品陈列</el-menu-item>
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-picture-outline"></i>
              <span slot="title">图片及排行</span>
            </template>
            <el-menu-item index="/rotationChart" :class="$route.path==='/rotationChart'?'is-active':''">轮播图设置</el-menu-item>
            <el-menu-item index="/settingIndexPicture" :class="$route.path==='/settingIndexPicture'?'is-active':''">首页产品设置</el-menu-item>
          </el-submenu>
          <el-menu-item index="/productureMessage" :class="$route.path==='/productureMessage'?'is-active':''">
            <i class="el-icon-setting"></i>
            <span slot="title">个人信息</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "ProductManager",
  data() {
    return {
      activeIndex: '',
      name: '',
      login: false
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleCommand(command) {
      this.$confirm('此操作将退出登录, 请问是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        sessionStorage.removeItem("boss")
        this.$router.push("/")
        this.$message({
          type: 'success',
          message: '退出成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  mounted() {
    this.activeIndex = this.$route.path
    let agency = JSON.parse(sessionStorage.getItem("agency"));
    let boss = JSON.parse(sessionStorage.getItem("boss"));
    if (agency !== null) {
      this.name = agency.aname
      return
    }
    if (boss !== null) {
      this.name = boss.bname
      return;
    }
    this.login = !this.login
  }
}
</script>

<style scoped>
.el-header {
  padding: 0;
}

.el-menu-demo {
  display: flex;
  flex-direction: row;
}

.header-title {
  padding-right: 50px;
  padding-left: 50px;
}

.header-user {
  margin-left: 950px;
  margin-top: 20px;
  color: white;
}
</style>
